/* $Id:general.h jjs $ */
/*
   Copyright (C) 2007 by Jurjen Stellingwerff <jurjen@stwerff.xs4all.nl>
   Part of the Moros Project http://moros.sourceforge.net/

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License version 3.
   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY.

   See the COPYING file for more details.
*/

#ifndef __GENERAL_H
#define __GENERAL_H

class invalid { /* .. */ };
class nullpointer { /* .. */ };
class unnamed { /* .. */ };

#define loopMap(r,v,t) \
    map<string,t>& v##_t=(r); \
    map<string,t> :: iterator v##_i = v##_t.begin(); \
    for( \
        t* v=&v##_i->second; \
        v##_i != v##_t.end(); \
        v##_i++, v=(v##_i != v##_t.end())?&v##_i->second:0 \
    )
#define loopMapi(r,v,t) \
    map<int,t>& v##_t=(r); \
    map<int,t> :: iterator v##_i = v##_t.begin(); \
    for( \
        t* v=&v##_i->second; \
        v##_i != v##_t.end(); \
        v##_i++, v=(v##_i != v##_t.end())?&v##_i->second:0 \
    )
#define loopSingle(r,v,t,s) \
    s<t>& v##_t=(r); \
    s<t> :: iterator v##_i = v##_t.begin(); \
    for( \
        t* v=&(*v##_i); \
        v##_i != v##_t.end(); \
        v##_i++, v=(v##_i != v##_t.end())?&(*v##_i):0 \
    )
#define loopArray(r,v,t) \
    const t *v=r; \
    unsigned int v##_c=sizeof r/sizeof r[0]; \
    for ( \
        unsigned int v##_i=0; \
        v##_i< v##_c; \
        v##_i++, v=(v##_i<v##_c)?r+v##_i:0 \
    )

#endif
